/*
Copyright 2007 Nathan Baker

This file is part of XAliens.

XAliens is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

XAliens is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with XAliens.  If not, see <http://www.gnu.org/licenses/>.
*/

package utils;

import javax.swing.*;

public class UserPrompt {

    public static final int YESNO = 0;
    public static final int YESNOCANCEL = 1;
    public static final int ERROR = 2;
    public static final int INFO = 3;

    public static final int USER_OK = 0;

    public static final int USER_YES = 0;
    public static final int USER_NO = 1;
    public static final int USER_CANCEL = 2;

    /**
     * Shows a message box prompt of a given type.
     *
     * @param prompt The string message to display to the user.
     * @param type   The Type of message box to show.
     * @return Button clicked by the user.
     */
    public static int messageBox(String prompt, int type) {
        int selectedValue;
        Object optionsOK[] = {"OK"};
        Object optionsYN[] = {"Yes", "No"};
        Object optionsYNC[] = {"Yes", "No", "Cancel"};

        switch (type) {
            case ERROR:
                selectedValue = JOptionPane.showOptionDialog(null, prompt, "",
                        JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE,
                        null, optionsOK, optionsOK[0]);

                break;
            case INFO:
                selectedValue = JOptionPane.showOptionDialog(null, prompt, "",
                        JOptionPane.DEFAULT_OPTION,
                        JOptionPane.INFORMATION_MESSAGE, null, optionsOK,
                        optionsOK[0]);

                break;
            case YESNO:
                selectedValue = JOptionPane.showOptionDialog(null, prompt, "",
                        JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
                        null, optionsYN, optionsYN[0]);

                break;
            case YESNOCANCEL:
                selectedValue = JOptionPane.showOptionDialog(null, prompt, "",
                        JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
                        null, optionsYNC, optionsYNC[0]);

                break;
            default:
                selectedValue = -1;
                break;
        }

        return selectedValue;
    }

    /**
     * @param msg
     */
    public static void print(String msg) {
        System.out.println(msg);
    }
}
